package com.group2.view;
import static model.netBase.IP;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.io.IOException;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.UIManager;
import javax.swing.border.EmptyBorder;
import model.*;

/*主界面：管理员视图
 * 功能：
 * 1.学生学籍信息管理
 * 2.选课系统管理
 * 3.图书馆管理
 * 4.校园商店管理
 * 5.校园银行管理
 * 6.用户密码修改
 * */

public class UserMainFrame_Admin extends javax.swing.JFrame {

	/* 检测打开了哪些窗口，退出登录时统一销毁 */
	private UserLogOnFrame Logon;// 返回登录
	private UserManageFrame_Admin UserAdmin;//用户管理(密码)
	private ShopMainFrame_Admin ShopAdmin;// 商店
	private CourseMainViewFrame_Admin CourseAdmin;// 课程
	private StudentMainFrame_Admin StudentAdmin;// 学籍
	private BankMainFrame_Admin BankAdmin;//银行
	private LibraryMainFrame_Admin LibraryAdmin;// 图书馆

	private String currentName;

	private JButton jb_student;
	private JButton jb_course;
	private JButton jb_library;
	private JButton jb_store;
	private JButton jb_bank;
	private JButton jb_user;
	private JButton jb_exit;

	private JLabel jlabel_1;
	private JLabel jlabel_2;
	private JLabel jlabel_3;
	private JLabel jlabel_4;
	private JLabel jlabel_5;
	private JLabel jlabel_6;
	private JLabel jlabel_main;

	private JPanel contentPane;

	public UserMainFrame_Admin(String name) {
		initComponents();
		Font font = new Font("微软雅黑", Font.PLAIN, 14);
		java.util.Enumeration keys = UIManager.getDefaults().keys();
		while (keys.hasMoreElements()) {
			Object key = keys.nextElement();
			Object value = UIManager.get(key);
			if (value instanceof javax.swing.plaf.FontUIResource) {
				UIManager.put(key, font);
			}
		}
		initComponents();
		setBounds(100, 200, 900, 700);
		this.setLocationRelativeTo(null);
		currentName = name;
	}

	private void initComponents() {

		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);

		jb_exit = new JButton("退出登录");
		jb_exit.setIcon(new javax.swing.ImageIcon(UserLogOnFrame.class.getResource("/images/exit.png")));
		jb_exit.setBounds(710, 20, 150, 28);
		jb_exit.setBorderPainted(false);
		jb_exit.setFocusPainted(false);
		jb_exit.setContentAreaFilled(false);
		contentPane.add(jb_exit);
		jb_exit.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				ExitActionPerformed(evt);
			}
		});

		setTitle("欢迎来到虚拟校园系统！Welcome to vCampus-Admin");
		
		jlabel_main = new JLabel();
		jlabel_main.setText("虚拟校园系统 · 管理员主界面");
		jlabel_main.setIcon(new javax.swing.ImageIcon(UserLogOnFrame.class.getResource("/images/campus.png")));
		jlabel_main.setFont(new java.awt.Font("微软雅黑", 1, 17));
		jlabel_main.setIconTextGap(15);
		jlabel_main.setBounds(303, 58, 339, 40);
		contentPane.add(jlabel_main);

		jb_student = new JButton();
		jb_student.setBounds(143, 120, 153, 153);
		jb_student.setBorderPainted(false);
		jb_student.setContentAreaFilled(false);
		jlabel_1 = new JLabel();
		jlabel_1.setText("学籍管理");
		jlabel_1.setBounds(187, 281, 69, 30);
		//jb_student.setFocusPainted(false);
		jb_student.setIcon(new javax.swing.ImageIcon(UserLogOnFrame.class.getResource("/images/StudentIcon1.png")));
		contentPane.add(jlabel_1);
		contentPane.add(jb_student);
		jb_student.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				StudentActionPerformed(evt);
			}
		});

		jb_course = new JButton();
		jlabel_2 = new JLabel("选课系统");
		jb_course.setBounds(389, 120, 153, 153);
		jlabel_2.setBounds(434, 281, 63, 30);
		jb_course.setBorderPainted(false);
		jb_course.setContentAreaFilled(false);
		//jb_course.setFocusPainted(false);
		jb_course.setIcon(new javax.swing.ImageIcon(UserLogOnFrame.class.getResource("/images/CourseIcon.png")));
		contentPane.add(jlabel_2);
		contentPane.add(jb_course);
		jb_course.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				try {
					CourseActionPerformed(evt);
				} catch (IOException e) {
					throw new RuntimeException(e);
				} catch (ClassNotFoundException e) {
					throw new RuntimeException(e);
				}
			}
		});

		jb_library = new JButton();
		jlabel_3 = new JLabel("图书馆");
		jb_library.setBounds(636, 120, 153, 153);
		jb_library.setBorderPainted(false);
		jb_library.setContentAreaFilled(false);
		jlabel_3.setBounds(682, 281, 50, 30);
		//jb_library.setFocusPainted(false);
		jb_library.setIcon(new javax.swing.ImageIcon(UserLogOnFrame.class.getResource("/images/LibraryIcon.png")));
		contentPane.add(jlabel_3);
		contentPane.add(jb_library);
		jb_library.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				try {
					LibraryActionPerformed(evt);
				} catch (IOException e) {
					throw new RuntimeException(e);
				} catch (ClassNotFoundException e) {
					throw new RuntimeException(e);
				}
			}
		});

		jb_store = new JButton();
		jlabel_4 = new JLabel("商店系统");
		jlabel_4.setBounds(187, 552, 75, 30);
		jb_store.setBounds(143, 376, 153, 153);
		jb_store.setBorderPainted(false);
		//jb_store.setFocusPainted(false);
		jb_store.setContentAreaFilled(false);
		jb_store.setIcon(new javax.swing.ImageIcon(UserLogOnFrame.class.getResource("/images/StoreIcon.png")));
		contentPane.add(jlabel_4);
		contentPane.add(jb_store);
		jb_store.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				StoreActionPerformed(evt);
			}
		});

		jb_bank = new JButton();
		jlabel_5 = new JLabel("银行");
		jb_bank.setBounds(389, 376, 153, 153);
		jlabel_5.setBounds(447, 552, 50, 30);
		//jb_bank.setFocusPainted(false);
		jb_bank.setBorderPainted(false);
		jb_bank.setContentAreaFilled(false);
		jb_bank.setIcon(new javax.swing.ImageIcon(UserLogOnFrame.class.getResource("/images/BankIcon.png")));
		contentPane.add(jlabel_5);
		contentPane.add(jb_bank);
		jb_bank.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				try {
					BankActionPerformed(evt);
				} catch (IOException e) {
					throw new RuntimeException(e);
				} catch (ClassNotFoundException e) {
					throw new RuntimeException(e);
				}
			}
		});

		jb_user = new JButton();
		jlabel_6 = new JLabel("用户管理");
		jb_user.setBounds(636, 376, 153, 153);
		jlabel_6.setBounds(682, 552, 69, 30);
		jb_user.setBorderPainted(false);
		jb_user.setContentAreaFilled(false);
		jb_user.setIcon(new javax.swing.ImageIcon(UserLogOnFrame.class.getResource("/images/UserIcon.png")));
		contentPane.add(jlabel_6);
		contentPane.add(jb_user);
		jb_user.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				try {
					UserActionPerformed(evt);
				} catch (IOException e) {
					throw new RuntimeException(e);
				} catch (ClassNotFoundException e) {
					throw new RuntimeException(e);
				}
			}
		});

	}

	// 学籍管理
	private void StudentActionPerformed(java.awt.event.ActionEvent evt) {
		StudentAdmin = new StudentMainFrame_Admin();
		StudentAdmin.setVisible(true);
		new ToolTip().setToolTip(new javax.swing.ImageIcon(UserLogOnFrame.class.getResource("/images/kefu.png")), 
				" 尊敬的管理员，管理学籍辛苦了！\n\n Q宝给你加油！");
	}

	// 选课系统
	private void CourseActionPerformed(java.awt.event.ActionEvent evt) throws IOException, ClassNotFoundException {
		CourseAdmin = new CourseMainViewFrame_Admin();
		CourseAdmin.setVisible(true);
		new ToolTip().setToolTip(new javax.swing.ImageIcon(UserLogOnFrame.class.getResource("/images/kefu.png")), 
				" 尊敬的管理员，管理课程辛苦了！\n\n Q宝给你加油！");
	}

	// 图书馆
	private void LibraryActionPerformed(java.awt.event.ActionEvent evt) throws IOException, ClassNotFoundException {
		LibraryAdmin = new LibraryMainFrame_Admin();
		LibraryAdmin.setVisible(true);
		new ToolTip().setToolTip(new javax.swing.ImageIcon(UserLogOnFrame.class.getResource("/images/kefu.png")), 
				" 尊敬的管理员，怎么图书馆也归你管啊！\n\n Q宝给你加油！");
	}

	// 商店
	private void StoreActionPerformed(java.awt.event.ActionEvent evt) {
		ShopAdmin = new ShopMainFrame_Admin();
		ShopAdmin.setVisible(true);
		new ToolTip().setToolTip(new javax.swing.ImageIcon(UserLogOnFrame.class.getResource("/images/kefu.png")), 
				" 尊敬的管理员，苏猫超市是什么鬼啊！\n\n Q宝给你加油！");
	}

	// 银行
	private void BankActionPerformed(java.awt.event.ActionEvent evt) throws IOException, ClassNotFoundException {
		BankAdmin = new BankMainFrame_Admin();
		BankAdmin.setVisible(true);
		new ToolTip().setToolTip(new javax.swing.ImageIcon(UserLogOnFrame.class.getResource("/images/kefu.png")), 
				" 尊敬的管理员，怎么银行也归你管啊！\n\n Q宝给你加油！");
	}

	// 退出登录
	private void ExitActionPerformed(java.awt.event.ActionEvent evt) {
		this.dispose();
		if (CourseAdmin instanceof CourseMainViewFrame_Admin) {
			CourseAdmin.dispose();
		}
		if (LibraryAdmin instanceof LibraryMainFrame_Admin) {
			LibraryAdmin.dispose();
		}
		if (StudentAdmin instanceof StudentMainFrame_Admin) {
			StudentAdmin.dispose();
		}
		if (UserAdmin instanceof UserManageFrame_Admin) {
			UserAdmin.dispose();
		}
		if (ShopAdmin instanceof ShopMainFrame_Admin) {
			ShopAdmin.dispose();
		}
		if (BankAdmin instanceof BankMainFrame_Admin) {
			BankAdmin.dispose();
		}

		new UserLogOnFrame().setVisible(true);
	}

	// 用户管理
	private void UserActionPerformed(java.awt.event.ActionEvent evt) throws IOException, ClassNotFoundException {
		UserAdmin = new UserManageFrame_Admin(currentName);
		UserAdmin.setVisible(true);
		new ToolTip().setToolTip(new javax.swing.ImageIcon(UserLogOnFrame.class.getResource("/images/kefu.png")), 
				" 尊敬的管理员，不要随便改别人的密码啊！\n\n Q宝给你加油！");
	}

	public static void main(String args[]) {
		java.awt.EventQueue.invokeLater(new Runnable() {
			public void run() {
				new UserMainFrame_Admin("").setVisible(true);
				new ToolTip().setToolTip(new javax.swing.ImageIcon(UserLogOnFrame.class.getResource("/images/kefu.png")), 
						" 尊敬的管理员，欢迎来到虚拟校园！\n\n 我是您真正人性化的智能助手Q宝！");
			}
		});
	}

}